package com.emex.app.stuff.provider;

import com.emex.app.shared.data.Cros;
import com.emex.app.shared.data.Position;
import com.emex.app.shared.ws.ShopWebService;
import com.emex.app.stuff.utils.WebServiceHelper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

/**
 *
 * @author Sergey
 */
public class ShopDataProvider extends Service {

    private ShopWebService service = null;

    private static ShopDataProvider instance = null;

    /**
     * Constructor
     */
    private ShopDataProvider() throws MalformedURLException {
        super(new URL(WebServiceHelper.getDefault().getWebServiceURL("web", "Shop")),
                WebServiceHelper.getDefault().getWebServiceQName("Shop"));
        service = getPort(ShopWebService.class);
    }

    /**
     * Get instance of data provider.
     *
     * @return data provider instance
     */
    public static synchronized ShopDataProvider getInstance() {
        if (instance == null) {
            new RequestWebService() {
                @Override
                protected void doRequestBody() throws MalformedURLException {
                    instance = new ShopDataProvider();
                }
            }.doRequest();
        }
        return instance;
    }

    public BindingProvider getBindingShop() {
        return (BindingProvider) service;
    }

    public int deletePosition(Integer id) {
        return service.deletePosition(id);
    }

    public Position insertPosition(Position record) {
        return service.insertPosition(record);
    }

    public Position getPositionById(Integer id) {
        return service.getPositionById(id);
    }

    public Position updatePosition(Position record) {
        return service.updatePosition(record);
    }

    public int deleteCros(Integer id) {
        return service.deleteCros(id);
    }

    public Cros insertCros(Cros record) {
        return service.insertCros(record);
    }

    public Cros getCrosById(Integer id) {
        return service.getCrosById(id);
    }

    public Cros updateCros(Cros record) {
        return service.updateCros(record);
    }

    public List<Position> getPositionByCode(String code) {
        return service.getPositionByCode(code);
    }

    public List<Position> getCrossPositionsByPositionId(Integer id) {
        return service.getCrossPositionsByPositionId(id);
    }

    public List<Position> getAllPosition() {
        return service.getAllPosition();
    }

    public void deleteCrosByPositions(Position p1, Position p2) {
        service.deleteCrosByPositions(p1, p2);
    }

    public List<Position> getPositionsToBuy() {
        return service.getPositionsToBuy();
    }
}
